# 面向对象特点：继承、多态、封装
class Player(object):  # 父类
    numbers = 0
    levels = ['青铜', '白银', '黄金', '铂金', '钻石', '王者']

    def __init__(self, name, age, city, level):
        self._name = name
        self._age = age
        self._city = city
        if level not in Player.levels:
            raise Exception("段位设置错误！")
        else:
            self.level = level
        Player.numbers += 1

    @property
    def name(self):
        return self._name

    @name.setter
    def name(self, name):
        if isinstance(name, str):
            self._name = name
        else:
            raise Exception("名字格式错误！")

    @property
    def age(self):
        return self._age

    @age.setter
    def age(self, age):
        if 0 < age < 200:
            self._age = age
        else:
            print("年龄设置错误！")

    @property
    def city(self):
        return self._city

    @city.setter
    def city(self, city):
        if 1 < len(city) < 10:
            self._city = city
        else:
            print("名字错误！")

    def level_up(self):
        current = self.levels.index(self.level)
        if current < len(self.levels) - 1:
            self.level = self.levels[current + 1]

    def show(self):  # 实例的方法
        print(f'我是荣耀王者的第{Player.numbers}个玩家，我的名字是{self.name}，我来自{self.city}，我的段位是{self.level}')

    def get_weapon(self, weapon):
        self.weapon = weapon

    @classmethod
    def get_Player(cls):
        print(f"一共有{Player.numbers}个玩家注册了王者荣耀")

    def show_weapon(self):
        return self.weapon.show_weapon()


class MVP(Player):  # 子类
    # 构造函数重写
    def __init__(self, name, age, city, level, coin):
        # 调用父类的构造函数
        super().__init__(name, age, city, level)
        self.coin = coin

    # 实例重写方法
    def show(self):  # 实例的方法
        print(f'我是荣耀王者的第{Player.numbers}个玩家，我的名字是{self.name}，'
              f'我来自{self.city}，我的段位是{self.level}，我的充值金额为：{self.coin}')


mia = MVP('mia', 24, '天津', '钻石', 100)
mia.city = '无锡'
mia.show()  # 先在子类中查找
